<?xml version="1.0" encoding="utf-8" ?> 
<sqlMap namespace="Leaveword"
	xmlns="http://ibatis.apache.org/mapping" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<alias>
		<typeAlias alias="Leaveword" type="Domain.Leaveword" />
	</alias>

	<resultMaps>
		<resultMap id="FullResultMap" class="Leaveword">
			<result property="id" column="id" dbType="Int"/>
			<result property="title" column="title" dbType="NVarChar"/>
			<result property="leavewordContent" column="leavewordContent" dbType="NText"/>
			<result property="addtime" column="addtime" dbType="DateTime"/>
			<result property="messagerName" column="messagerName" dbType="NVarChar"/>
			<result property="messagerEmail" column="messagerEmail" dbType="NVarChar"/>
			<result property="messagerTel" column="messagerTel" dbType="NVarChar"/>
			<result property="replyContent" column="replyContent" dbType="NText"/>
			<result property="replyTime" column="replyTime" dbType="DateTime"/>
			<result property="replyId" column="replyId" dbType="Int"/>
		</resultMap>
	</resultMaps>
	
	<statements>

		<select id="GetCount" resultClass="System.Int32">
			SELECT count(*) FROM [dbo].[leaveword]
		</select>
		
		<select id="GetCountByCondition" parameterClass="Hashtable" resultClass="System.Int32" extends="GetCount">
			WHERE $condition$
		</select>
		
		<select id="FindAll" resultClass="Leaveword">
			SELECT * 
			FROM [dbo].[leaveword]
		</select>
		
		<select id="GetModel" parameterClass="Leaveword" resultClass="Leaveword" extends="FindAll">
			WHERE
				([leaveword].[id] = #id,dbType=Int#)
		</select>

		<insert id="Insert" parameterClass="Leaveword">
			INSERT INTO [dbo].[leaveword] (
				[title] , 
				[leavewordContent] , 
				[addtime] , 
				[messagerName] , 
				[messagerEmail] , 
				[messagerTel] 
			) VALUES (
				 #title,dbType=NVarChar# , 
				 #leavewordContent,dbType=NText# , 
				 #addtime,dbType=DateTime# , 
				 #messagerName,dbType=NVarChar# , 
				 #messagerEmail,dbType=NVarChar# , 
				 #messagerTel,dbType=NVarChar# 
			)
		</insert>

		<update id="Update" parameterClass="Leaveword">
			UPDATE [dbo].[leaveword] SET
				 [title] = #title,dbType=NVarChar#
				, [leavewordContent] = #leavewordContent,dbType=NText#
				, [addtime] = #addtime,dbType=DateTime#
				, [messagerName] = #messagerName,dbType=NVarChar#
				, [messagerEmail] = #messagerEmail,dbType=NVarChar#
				, [messagerTel] = #messagerTel,dbType=NVarChar#
				, [replyContent] = #replyContent,dbType=NText#
				, [replyTime] = #replyTime,dbType=DateTime#
				, [replyId] = #replyId,dbType=Int#
			WHERE
				([id] = #id,dbType=Int#)
		</update>

		<delete id="Delete" parameterClass="Leaveword">
			DELETE FROM [dbo].[leaveword]
			WHERE
				([id] = #id,dbType=Int#)
		</delete>

		<select id="GetModelsByCondition" parameterClass="Hashtable" resultClass="Leaveword">
			SELECT $columnNames$ FROM [dbo].[leaveword] where $condition$
		</select>
		
		<select id="GetModelsByConditionByPager" parameterClass="Hashtable" resultClass="Leaveword">
      declare @indextable table(rno int identity(1,1),nid int)
      insert into @indextable(nid) select [id] from [dbo].[leaveword]
      where $condition$ order by $orderBy$

      select $columnNames$ from
      [dbo].[leaveword] ,@indextable t
      <![CDATA[
			where t.nid= [leaveword].id and t.rno>#startNo# and t.rno<=#endNo# 
      order by t.rno asc
			]]>
		</select>
		
	</statements>
</sqlMap>
